<?php
class BookModel extends Model{
	//获取全部图书
	public function getAllBook(){
		$sql="SELECT tb_bookinfo.*, tb_bookcase.name, tb_booktype.typename, publishing.pubname 
				from tb_bookinfo 
				left JOIN tb_bookcase ON tb_bookinfo.bookcase = tb_bookcase.id 
				left JOIN tb_booktype ON tb_bookinfo.typeid = tb_booktype.id 
				left JOIN tb_publishing AS publishing ON tb_bookinfo.ISBN = publishing.ISBN";
		return $this->db->getAll($sql);
	}
	//分页获取图书
	/**
	 * @param int $offset 偏移量
	 * @param int $pagesize 每页显示条数
	 * 返回包含结果集的二维数组
	 */
	public function getBooks($offset,$pagesize){
		$sql="SELECT tb_bookinfo.*, tb_bookcase.name, tb_booktype.typename, publishing.pubname 
				from tb_bookinfo 
				left JOIN tb_bookcase ON tb_bookinfo.bookcase = tb_bookcase.id 
				left JOIN tb_booktype ON tb_bookinfo.typeid = tb_booktype.id 
				left JOIN tb_publishing AS publishing ON tb_bookinfo.ISBN = publishing.ISBN 
				where tb_bookinfo.del=0
				order by tb_bookinfo.id desc 
				LIMIT {$offset},{$pagesize}";
		return $this->db->getAll($sql);
	}
	
	//获取所有的图书类型
	public function getAllBookType(){
		$sql="select * from tb_booktype";
		return $this->db->getAll($sql);
	}
	
	//获取所有出版社
	public function getAllPublishing(){
		$sql="select * from tb_publishing";
		return $this->db->getAll($sql);
	}
	
	//获取所有书架
	public function getAllBookCase(){
		$sql="select * from tb_bookcase";
		return $this->db->getAll($sql);
	}
	
	//根据图书条形码查询一条图书信息
	
	public function getOneInfo($barcode){
		$sql="SELECT tb_bookinfo.*, tb_bookcase.name, tb_booktype.typename, publishing.pubname 
				from tb_bookinfo 
				left JOIN tb_bookcase ON tb_bookinfo.bookcase = tb_bookcase.id 
				left JOIN tb_booktype ON tb_bookinfo.typeid = tb_booktype.id 
				left JOIN tb_publishing AS publishing ON tb_bookinfo.ISBN = publishing.ISBN 
				where tb_bookinfo.del=0 and tb_bookinfo.barcode={$barcode}";
		return $this->db->getRow($sql);
	}
	
	
	
	
}















